package com.xuecheng.manage_cms.service;

import com.xuecheng.api.cms.CmsPageTemplateControllerApi;
import com.xuecheng.framework.domain.cms.CmsTemplate;
import com.xuecheng.framework.model.response.CommonCode;
import com.xuecheng.framework.model.response.QueryResponseResult;
import com.xuecheng.framework.model.response.QueryResult;
import com.xuecheng.manage_cms.dao.CmsPageTemplateRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Created by Aniymx on 2018/12/20 21:02.
 * 模板业务层
 */
@Service
public class CmsPageTemplateService implements CmsPageTemplateControllerApi {
    @Autowired
    private CmsPageTemplateRepository cmsPageTemplateRepository;

    public QueryResponseResult findAllTemplate() {
        List<CmsTemplate> all = cmsPageTemplateRepository.findAll();
        QueryResult<CmsTemplate> cmsTemplateQueryResult = new QueryResult<>();
        cmsTemplateQueryResult.setList(all);
        return new QueryResponseResult(CommonCode.SUCCESS, cmsTemplateQueryResult);
    }

    public CmsTemplate findById(String id){
        Optional<CmsTemplate> optional = cmsPageTemplateRepository.findById(id);
        if (optional.isPresent()){
            CmsTemplate cmsTemplate = optional.get();
            return cmsTemplate;
        }
        return null;
    }

}
